/*
 * Chastoslov
 * Copyright (C) 2009 Alexandr Stroghov
 * 
 * stroghov@gmail.com
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of the 
 * GNU General Public License, version 2, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program; if 
 * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 * MA 02111-1307 USA
*/
package world.ah.wf.guiclient;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

public class OptionsHolder {
  public static final int LOOK_AND_FEEL_USE_DEFAULT = 0;
  public static final int LOOK_AND_FEEL_USE_SYSTEM = 1;
  public static final int LOOK_AND_FEEL_USE_CUSTOM = 2;
  //
  private int lookAndFeelUsageKind;
  public void setLookAndFeelUsageKind(int lookAndFeelUsageKind) {
    if(lookAndFeelUsageKind < 0 || lookAndFeelUsageKind > 2)
      this.lookAndFeelUsageKind = LOOK_AND_FEEL_USE_DEFAULT;
    else this.lookAndFeelUsageKind = lookAndFeelUsageKind;
  }
  public int getLookAndFeelUsageKind() {return lookAndFeelUsageKind;}  
  //
  private String LookAndFeelClassName;
  public void setLookAndFeelClassName(String LookAndFeelClassName) {
    this.LookAndFeelClassName = LookAndFeelClassName;
  }
  public String getLookAndFeelClassName() {return LookAndFeelClassName;}
  // Файл языка
  private String LanguageFileName = "";
  public String getLanguageFileName() {return LanguageFileName;}
  public void setLanguageFileName(String LanguageFileName) {this.LanguageFileName = LanguageFileName;}
  //
  
  
  //
  private String propertiesFileName;
  public void setPropertiesFileName(String propertiesFileName) {
    this.propertiesFileName = propertiesFileName;
  }
  public String getPropertiesFileName() {return propertiesFileName;}
  //
  public OptionsHolder () {
    this.setPropertiesFileName("");
    this.setLookAndFeelUsageKind(0);
    this.setLookAndFeelClassName("");
  }
  // Загружает параметры из файла 
  public void loadProperties() throws Exception {
    if(propertiesFileName.length() < 1) throw new Exception("Properties file name not defined");
    Properties prop = new Properties();
    prop.load (new FileInputStream(this.propertiesFileName));
    //
    //String s;
    int i;
    try {i = Integer.parseInt(prop.getProperty("lookAndFeelUsageKind", "0"));}
    catch (Exception ex) {i = 0;}
    this.setLookAndFeelUsageKind(i);
    this.setLookAndFeelClassName(prop.getProperty("lookAndFeelClassName", ""));
    this.setLanguageFileName(prop.getProperty("languageFileName", ""));
    //String s = prop.getProperty("autoConnect", "false");
    //this.setAutoConnect(new Boolean(s).booleanValue());
  };
  // Сохраняет параметры в файл 
  public void saveProperties() throws Exception {
    Properties prop = new Properties();
    prop.setProperty("lookAndFeelUsageKind", Integer.toString(this.getLookAndFeelUsageKind()));
    prop.setProperty("lookAndFeelClassName", this.getLookAndFeelClassName());
    prop.setProperty("languageFileName", this.getLanguageFileName());
    prop.store(new FileOutputStream(this.propertiesFileName), "Program options");
  }







}